<?php


namespace app\miniapp\controller;


use app\common\controller\Api;
use app\miniapp\model\DetailModel;

class Detail extends Base
{
    protected $noNeedLogin = '*';

    //首页列表推荐
    public function list1()
    {
        $data = DetailModel::order('id','DESC')
            ->field('id,image,name,profilee,sales,money,deposit')
            ->select();
        if (!$data) {
            $this->error('错误');
        }
        $this->success('查询成功',[
            'list' => $data
        ]);
    }

    //分类产品列表
    public function list2()
    {
        $menuId = input('menuId/d');
        $sales = input('sales');
        $money = input('money');
        if (empty($menuId)) {
            $this->error('分类ID不能为空');
        }
        $order = [];
        if ($sales) {
            $order['sales'] = $sales;
        }
        if ($money) {
            $order['money'] = $money;
        }
        $list = DetailModel::where('procate',$menuId)
            ->order($order)
            ->field('id,image,name,profilee,sales,money,deposit')
            ->select();
        if (!$list) {
            $this->error('错误');
        }
        $this->success('查询成功',[
            'list' => $list
        ]);
    }

    //产品详情
    public function detail()
    {
        $id = input('id/d');
        if (empty($id)) {
            $this->error('ID不能为空');
        }
        $data = DetailModel::field('id,images,name,profilee,rulecontent,sales,money,deposit')->find($id);
        if (!$data) {
            $this->error('错误');
        }
        $this->success('查询成功',[
            'detail' => $data
        ]);

    }

}